<template>
  <div class="loginBox">
    <el-row type="flex"
            class="row-bg"
            justify="center">
      <el-col :span="6">
        <h2>京东商品信息后台管理系统</h2>
        <el-form :model="userForm">
          <el-form-item label="用户名">
            <el-input v-model="userForm.username"
                      placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="userForm.password"
                      placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="danger"
                       class="loginButton"
                       @click="login">登录</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'Login',

  data () {
    return {
      userForm: {
        username: '',
        password: ''
      }
    };
  },

  mounted () {

  },

  methods: {
    login () {
      this.$axios.get('/users?username=' + this.userForm.username).then(res => {
          console.log(res.data);
        if (this.userForm.username == res.data[0].username && this.userForm.password == res.data[0].password) {
          this.$notify({
            title: '登录成功',
            message: '登录成功',
            type: 'success'
          });
          this.$router.push('/home')
          let data = {
            username: this.userForm.username
          }
          window.sessionStorage.setItem('myAppAdmin', JSON.stringify(data))
        } else {
          this.$notify.error({
            title: '登录失败',
            message: '登录失败',
          });
        //   this.userForm.username = ""
        //   this.userForm.password = ""
        }
      })
    }
  },
};
</script>

<style scoped>
.loginBox {
  width: 100%;
  background-image: url('../assets/header.png');
  background-size: cover;
  height: 100vh;
}
.loginBox h2 {
  text-align: center;
  margin-top: 180px;
  margin-bottom: 20px;
  color: #eee;
}
.loginBox .loginButton {
  width: 100%;
}
</style>